﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Configuration;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.IO;
using System.Drawing.Drawing2D;
using Microsoft.Win32;
using System.Collections;
using System.Runtime.InteropServices;
using System.Xml;
using System.Drawing.Imaging;
namespace 会员卡管理系统.Vipclass
{
    class tbVipHouseMenthod
    {
        OleDbCommand oledcmd = null;
        OleDbConnection oledCon = null;
        OleDbDataReader oleRed = null;
        tb_viphouseinfo _aut1 = null;
        /// <summary>
        /// 添加会员
        /// </summary>
        /// <param name="tb_aut"></param>
        /// <returns></returns>
        public int tbvipfoadd(tb_viphouseinfo tb_aut)
        {
            int intResesult = 0;
            try
            {
                getConnection getCon = new getConnection();
                oledCon = getCon.OledCon();
                oledCon.Open();
                string strAdd = "insert into Vip_Table(vipid,vipname,vipidcard) values ( ";
                strAdd += "'" + tb_aut.Strvipid + "','" + tb_aut.Strvipname + "','" + tb_aut.Strvipidcard + "')";
                oledcmd = new OleDbCommand(strAdd, oledCon);
                intResesult = oledcmd.ExecuteNonQuery();
                return intResesult;
            }
            catch(Exception err)
            {
                MessageBox.Show(err.Message.ToString());
                return intResesult;
            }
        }
        /// <summary>
        /// 修改会员信息
        /// </summary>
        /// <param name="tb_aut"></param>
        /// <returns></returns>
        public int tbvipfoupdate(tb_viphouseinfo tb_aut)
        {
            int intResult = 0;
            try
            {
                getConnection getCon = new getConnection();
                oledCon = getCon.OledCon();
                oledCon.Open();
                string strupdate = "update Vip_Table set ";
                strupdate += "vipname ='" + tb_aut.Strvipname + "',vipidcard='" + tb_aut.Strvipidcard + "' where vipid='" + tb_aut.Strvipid + "'";
                oledcmd = new OleDbCommand(strupdate, oledCon);
                intResult = oledcmd.ExecuteNonQuery();
                return intResult;
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message.ToString());
                return intResult;
            }
        }
        /// <summary>
        /// 删除会员
        /// </summary>
        /// <param name="tb_aut"></param>
        /// <returns></returns>
        public int tbvipfodel(string tb_aut)
        {
            int intResult = 0;
            try
            {
                getConnection getCon = new getConnection();
                oledCon = getCon.OledCon();
                oledCon.Open();
                string strdel = "delete * from Vip_Table where vipname='" + tb_aut + "'";
                oledcmd = new OleDbCommand(strdel, oledCon);
                intResult = oledcmd.ExecuteNonQuery();
                return intResult;
            }
            catch(Exception err)
            {
                MessageBox.Show(err.Message, ToString());
                return intResult;
                
            }

        }
        /// <summary>
        /// 将Vip_Table表中的信息填入listview控件中
        /// </summary>
        /// <param name="obj"></param>
        public void tbVipfoFill(object obj,ImageList img)
        {
            try
            {
                getConnection getCon = new getConnection();
                oledCon = getCon.OledCon();
                oledCon.Open();
                string strRed = "select * from Vip_Table";
                oledcmd = new OleDbCommand(strRed, oledCon);
                oleRed = oledcmd.ExecuteReader();
                ListView lv = (ListView)obj;
                lv.Items.Clear();
                lv.LargeImageList = img;
                while (oleRed.Read())
                {
                    lv.Items.Add(oleRed[1].ToString(), 0);
                }
                oleRed.Close();
            }
            catch(Exception err)
            {
                MessageBox.Show(err.Message.ToString());
            }
        }
        /// <summary>
        /// Vipmanage 模糊查询
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="img"></param>
        /// <param name="strfind"></param>
        public void tbVipfoFind(object obj, ImageList img, string strfind,int way)
        {
            try
            {
                getConnection getCon = new getConnection();
                oledCon = getCon.OledCon();
                oledCon.Open();
                string strRed=null;
                switch(way)
                {
                    case 0:
                        strRed = "select * from Vip_Table where vipid like '%" + strfind + "%'";
                        break;
                    case 1:
                        strRed = "select * from Vip_Table where vipname like '%" + strfind + "%'";
                        break;
                    case 2:
                        strRed = "select * from Vip_Table where vipidcard like '%" + strfind + "%'";
                        break;
                }
                oledcmd = new OleDbCommand(strRed, oledCon);
                oleRed = oledcmd.ExecuteReader();
                ListView lv = (ListView)obj;
                lv.Items.Clear();
                lv.LargeImageList = img;
                while (oleRed.Read())
                {
                    lv.Items.Add(oleRed[1].ToString(), 0);
                }
                oleRed.Close();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message.ToString());
            }
        }
        /// <summary>
        /// 显示相应会员信息
        /// </summary>
        /// <param name="strshow"></param>
        /// <returns></returns>
        public tb_viphouseinfo tbViptoshow(string strshow)
        {
            _aut1 = new tb_viphouseinfo();
            try
            {
                getConnection getCon = new getConnection();
                oledCon = getCon.OledCon();
                oledCon.Open();
                string strRed = "select * from Vip_Table where vipname='" + strshow + "'";
                oledcmd = new OleDbCommand(strRed, oledCon);
                oleRed = oledcmd.ExecuteReader();
                oleRed.Read();
                _aut1.Strvipid = oleRed[0].ToString();
                _aut1.Strvipname = oleRed[1].ToString();
                _aut1.Strvipidcard = oleRed[2].ToString();
                _aut1.Intgivetime = (int)oleRed[3];
                _aut1.Intalltime = (int)oleRed[4];
                oleRed.Close();
                return _aut1;
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message.ToString());
                return _aut1;
            }
        }
        /// <summary>
        /// 将会员入住记录添加到listview中
        /// </summary>
        /// <param name="obj"></param>
        public void tbVipRecordfoFill(object obj,string strvip)
        {
            try
            {
                getConnection getCon = new getConnection();
                oledCon = getCon.OledCon();
                oledCon.Open();
                string strRed = "select * from House_Record where vipname='"+strvip+"'";
                oledcmd = new OleDbCommand(strRed, oledCon);
                oleRed = oledcmd.ExecuteReader();
                ListView lv = (ListView)obj;
                lv.Items.Clear();
                while (oleRed.Read())
                {
                    ListViewItem lv1 = new ListViewItem(oleRed[1].ToString());
                    lv1.SubItems.Add(oleRed[3].ToString());
                    lv1.SubItems.Add(oleRed[5].ToString());
                    lv1.SubItems.Add(oleRed[6].ToString());
                    lv.Items.Add(lv1);
                }
                oleRed.Close();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message.ToString());
            }
        }
        /// <summary>
        /// 将House_Table表中的数据填充道listview中
        /// </summary>
        /// <param name="obj"></param>
        public tb_viphouseinfo tbHousefoFill(object obj,ImageList img)
        {
            int housenum = 0;
            int hasuse = 0;
            int nouse = 0;
            _aut1 = new tb_viphouseinfo();
            try
            {
                getConnection getCon = new getConnection();
                oledCon = getCon.OledCon();
                oledCon.Open();
                string strRed = "select * from House_Table";
                oledcmd = new OleDbCommand(strRed, oledCon);
                oleRed = oledcmd.ExecuteReader();
                ListView lv = (ListView)obj;
                lv.Items.Clear();
                lv.LargeImageList = img;
                while (oleRed.Read())
                {
                    if (oleRed[1].ToString() == "0")
                    {
                        lv.Items.Add(oleRed[0].ToString(), 0);
                        nouse++;
                    }
                    else
                    {
                        lv.Items.Add(oleRed[0].ToString(), 1);
                        
                        hasuse++;
                    }
                    housenum++;
                }
                oleRed.Close();
                _aut1.Inthousenum = housenum;
                _aut1.Inthasuse = hasuse;
                _aut1.Intnouse = nouse;
                return _aut1;
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message.ToString());
                return _aut1;
            }
        }
        /// <summary>
        /// HouseManage模糊查询
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="img"></param>
        /// <param name="strfind"></param>
        public void tbHousefoFind(object obj, ImageList img,string strfind)
        {
            try
            {
                getConnection getCon = new getConnection();
                oledCon = getCon.OledCon();
                oledCon.Open();
                string strRed = "select * from House_Table where houseid like '%"+strfind+"%'";
                oledcmd = new OleDbCommand(strRed, oledCon);
                oleRed = oledcmd.ExecuteReader();
                ListView lv = (ListView)obj;
                lv.Items.Clear();
                lv.LargeImageList = img;
                while (oleRed.Read())
                {
                    if (oleRed[1].ToString() == "0")
                    {
                        lv.Items.Add(oleRed[0].ToString(), 0);
                    }
                    else
                    {
                        lv.Items.Add(oleRed[0].ToString(), 1);
                    }
                }
                oleRed.Close();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message.ToString());
            }
        }
        /// <summary>
        /// 显示对应房间信息
        /// </summary>
        /// <param name="strshow"></param>
        /// <returns></returns>
        public tb_viphouseinfo tbHousetoshow(string strshow)
        {
            _aut1 = new tb_viphouseinfo();
            try
            {
                getConnection getCon = new getConnection();
                oledCon = getCon.OledCon();
                oledCon.Open();
                string strRed = "select * from House_Table where houseid='" + strshow + "'";
                oledcmd = new OleDbCommand(strRed, oledCon);
                oleRed = oledcmd.ExecuteReader();
                oleRed.Read();
                _aut1.Bolhousestay = (int)oleRed[1];
                _aut1.Intusetime =(int)oleRed[2];
                if (_aut1.Bolhousestay == 1)
                {
                    _aut1.Strvipid = oleRed[3].ToString();
                    _aut1.Strvipname = oleRed[4].ToString();
                    _aut1.Dtusedate = (DateTime)oleRed[5];
                }
                oleRed.Close();
                return _aut1;
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message.ToString());
                return _aut1;
            }
        }
        /// <summary>
        /// 将房间入住记录添加到listview中
        /// 
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="strhouse"></param>
        public void tbHouseRecordfoFill(object obj, string strhouse)
        {
            try
            {
                getConnection getCon = new getConnection();
                oledCon = getCon.OledCon();
                oledCon.Open();
                string strRed = "select * from House_Record where houseid='" + strhouse + "'";
                oledcmd = new OleDbCommand(strRed, oledCon);
                oleRed = oledcmd.ExecuteReader();
                ListView lv = (ListView)obj;
                lv.Items.Clear();
                while (oleRed.Read())
                {
                    ListViewItem lv1 = new ListViewItem(oleRed[1].ToString());
                    lv1.SubItems.Add(oleRed[3].ToString());
                    lv1.SubItems.Add(oleRed[5].ToString());
                    lv1.SubItems.Add(oleRed[6].ToString());
                    lv.Items.Add(lv1);
                }
                oleRed.Close();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message.ToString());
            }
        }
        //public  int tbviptimeadd(tb_viphouseinfo tb_aut)
        //{
        //    int intResult = 0;
        //    try
        //    {
        //        getConnection getCon = new getConnection();
        //        oledCon = getCon.OledCon();
        //        oledCon.Open();
        //        string strdel = "update Vip_Table set";
        //        oledcmd = new OleDbCommand(strdel, oledCon);
        //        intResult = oledcmd.ExecuteNonQuery();
        //        return intResult;
        //    }
        //    catch
        //    {
        //        return intResult;
        //    }
        //}
        /// <summary>
        /// 添加房间
        /// </summary>
        /// <param name="tb_aut"></param>
        /// <returns></returns>
        public int tbhousefoadd(tb_viphouseinfo tb_aut)
        {
            int intResult = 0;
            try
            {
                getConnection getCon = new getConnection();
                oledCon = getCon.OledCon();
                oledCon.Open();
                string stradd = "insert into House_Table (houseid)values('"+tb_aut.Strhouseid+"')";
                oledcmd = new OleDbCommand(stradd, oledCon);
                intResult = oledcmd.ExecuteNonQuery();
                return intResult;
            }
            catch(Exception err)
            {
                MessageBox.Show(err.Message.ToString());
                return intResult;
            }
        }
        
        /// <summary>
        /// 删除房间
        /// </summary>
        /// <param name="tb_aut"></param>
        /// <returns></returns>
        public int tbhousefodel(string tb_aut)
        {
            int intResult = 0;
            try
            {
                getConnection getCon = new getConnection();
                oledCon = getCon.OledCon();
                oledCon.Open();
                string strdel = "delete * from House_Table where houseid='"+tb_aut+"'";
                oledcmd = new OleDbCommand(strdel, oledCon);
                intResult = oledcmd.ExecuteNonQuery();
                return intResult;
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message.ToString());
                return intResult;
            }
        }
        /// <summary>
        /// 将数据填入Recordmanege中 
        /// </summary>
        /// <param name="obj"></param>
        public void tbMainRecordfoFill(object obj)
        {
            try
            {
                getConnection getCon = new getConnection();
                oledCon = getCon.OledCon();
                oledCon.Open();
                string strRed = "select * from House_Record ";
                oledcmd = new OleDbCommand(strRed, oledCon);
                oleRed = oledcmd.ExecuteReader();
                ListView lv = (ListView)obj;
                lv.Items.Clear();
                while (oleRed.Read())
                {
                    ListViewItem lv1 = new ListViewItem(oleRed[0].ToString());
                    lv1.SubItems.Add(oleRed[1].ToString());
                    lv1.SubItems.Add(oleRed[2].ToString());
                    lv1.SubItems.Add(oleRed[3].ToString());
                    lv1.SubItems.Add(oleRed[4].ToString());
                    lv1.SubItems.Add(oleRed[5].ToString());
                    lv1.SubItems.Add(oleRed[6].ToString());
                    lv.Items.Add(lv1);
                }
                oleRed.Close();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message.ToString());
            }
        }
        /// <summary>
        /// 获取记录相关的信息
        /// </summary>
        /// <param name="strshow"></param>
        /// <returns></returns>
        public tb_viphouseinfo tbRecordtoshow(string strshow)
        {
            _aut1 = new tb_viphouseinfo();
            try
            {
                getConnection getCon = new getConnection();
                oledCon = getCon.OledCon();
                oledCon.Open();
                string strRed = "select * from House_Record where id='" + strshow + "'";
                oledcmd = new OleDbCommand(strRed, oledCon);
                oleRed = oledcmd.ExecuteReader();
                oleRed.Read();
                _aut1.Strhouseid = oleRed[1].ToString();
                _aut1.Strvipid = oleRed[2].ToString();
                _aut1.Strvipname = oleRed[3].ToString();
                _aut1.Strvipidcard = oleRed[4].ToString();
                _aut1.Dtusedate = (DateTime)oleRed[5];
                _aut1.Dtleavedate = (DateTime)oleRed[6];
                oleRed.Close();
                return _aut1;
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message.ToString());
                return _aut1;
            }
        }
        /// <summary>
        /// 删除相关记录
        /// </summary>
        /// <param name="tb_aut"></param>
        /// <returns></returns>
        public int tbrecordfodel(string tb_aut)
        {
            int intResult = 0;
            try
            {
                getConnection getCon = new getConnection();
                oledCon = getCon.OledCon();
                oledCon.Open();
                string strdel = "delete * from House_Record where id='" + tb_aut + "'";
                oledcmd = new OleDbCommand(strdel, oledCon);
                intResult = oledcmd.ExecuteNonQuery();
                return intResult;
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message.ToString());
                return intResult;
            }
        }
        /// <summary>
        /// 记录检索
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="strfind"></param>
        /// <param name="way"></param>
        public void tbRecordfoFind(object obj, string strfind, int way,string minDt,string maxDt)
        {
            try
            {
                getConnection getCon = new getConnection();
                oledCon = getCon.OledCon();
                oledCon.Open();
                string strRed = null;
                switch (way)
                {
                    case 0:
                        strRed = "select * from House_Record where houseid like '%" + strfind + "%'and [usedate]>#" + minDt + "# and [leavedate]<#" + maxDt + "#";
                        break;
                    case 1:
                        strRed = "select * from House_Record where vipname like '%" + strfind + "%'and [usedate]>#" + minDt + "# and [leavedate]<#" + maxDt + "#";
                        break;
                    case 2:
                        strRed = "select * from House_Record where vipidcard like '%" + strfind + "%'and [usedate]>#" + minDt + "# and [leavedate]<#" + maxDt + "#";
                        break;
                    case 3:
                        strRed = "select * from House_Record where vipid like '%" + strfind + "%'and [usedate]>#" + minDt + "# and [leavedate]<#" + maxDt + "#";
                        break;
                }
                oledcmd = new OleDbCommand(strRed, oledCon);
                oleRed = oledcmd.ExecuteReader();
                ListView lv = (ListView)obj;
                lv.Items.Clear();
                while (oleRed.Read())
                {
                    ListViewItem lv1 = new ListViewItem(oleRed[0].ToString());
                    lv1.SubItems.Add(oleRed[1].ToString());
                    lv1.SubItems.Add(oleRed[2].ToString());
                    lv1.SubItems.Add(oleRed[3].ToString());
                    lv1.SubItems.Add(oleRed[4].ToString());
                    lv1.SubItems.Add(oleRed[5].ToString());
                    lv1.SubItems.Add(oleRed[6].ToString());
                    lv.Items.Add(lv1);
                }
                oleRed.Close();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message.ToString());
            }
        }
        ///// <summary>
        ///// 记录管理日期检索
        ///// </summary>
        ///// <param name="obj"></param>
        ///// <param name="minDt"></param>
        ///// <param name="maxDt"></param>
        ///// <returns></returns>
        //public tb_viphouseinfo tbRecordDatefond(object obj, string minDt,string maxDt)
        //{
        //    _aut1 = new tb_viphouseinfo();
        //    try
        //    {
        //        getConnection getCon = new getConnection();
        //        oledCon = getCon.OledCon();
        //        oledCon.Open();
        //        string strRed = "select * from House_Record where [usedate]>#" + minDt + "# and [leavedate]<#"+maxDt+"#";
        //        oledcmd = new OleDbCommand(strRed, oledCon);
        //        oleRed = oledcmd.ExecuteReader();
        //        ListView lv = (ListView)obj;
        //        lv.Items.Clear();
        //        while (oleRed.Read())
        //        {
        //            ListViewItem lv1 = new ListViewItem(oleRed[0].ToString());
        //            lv1.SubItems.Add(oleRed[1].ToString());
        //            lv1.SubItems.Add(oleRed[2].ToString());
        //            lv1.SubItems.Add(oleRed[3].ToString());
        //            lv1.SubItems.Add(oleRed[4].ToString());
        //            lv1.SubItems.Add(oleRed[5].ToString());
        //            lv1.SubItems.Add(oleRed[6].ToString());
        //            lv.Items.Add(lv1);
        //        }
        //        oleRed.Close();
        //        return _aut1;
        //    }
        //    catch(Exception err)
        //    {
        //        MessageBox.Show(err.Message.ToString());
        //        return _aut1;
        //    }
        //}

            /// <summary>
            /// 加载房间信息到cbx
            /// </summary>
            /// <param name="obj"></param>
        public void tbNorusefoFill(object obj)
        {
            try
            {
                getConnection getCon = new getConnection();
                oledCon = getCon.OledCon();
                oledCon.Open();
                string strRed = "select * from House_Table";
                oledcmd = new OleDbCommand(strRed, oledCon);
                oleRed = oledcmd.ExecuteReader();
                ComboBox cbx = (ComboBox)obj;
                cbx.Items.Clear();
                while (oleRed.Read())
                {
                    if(oleRed[1].ToString()=="0")
                    {
                        cbx.Items.Add(oleRed[0].ToString());
                    }
                }
                if(cbx.Items.Count>0)
                {
                    cbx.SelectedIndex = 0;
                }
                oleRed.Close();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message.ToString());
            }
        }
        /// <summary>
        /// 普通入住
        /// </summary>
        /// <param name="tb_aut"></param>
        /// <returns></returns>
        public int tbhousefoNoruse(tb_viphouseinfo tb_aut)
        {
            int intResult = 0;
            try
            {
                getConnection getCon = new getConnection();
                oledCon = getCon.OledCon();
                oledCon.Open();
                string struse="select * from House_Table where houseid='"+tb_aut.Strhouseid+"'";
                oledcmd = new OleDbCommand(struse, oledCon);
                oleRed = oledcmd.ExecuteReader();
                oleRed.Read();
                if ((int)oleRed[1] == 0)
                {
                    int usetime = (int)oleRed[2] + 1;
                    string strupdate = "update House_Table set housestay='" + tb_aut.Bolhousestay + "',usetime='" + usetime + "',vipname='" + tb_aut.Strvipname + "',vipid='" + tb_aut.Strvipidcard + "',usedate=#" + DateTime.Now + "# where houseid='" + tb_aut.Strhouseid + "'";
                    oledcmd = new OleDbCommand(strupdate, oledCon);
                    intResult = oledcmd.ExecuteNonQuery();
                    oleRed.Close();
                }
                return intResult;
                
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message.ToString());
                return intResult;
            }
        }
        /// <summary>
        /// 会员入住（房间表操作）
        /// </summary>
        /// <param name="tb_aut"></param>
        /// <returns></returns>
        public int tbhousefoVipuse(tb_viphouseinfo tb_aut)
        {
            int intResult = 0;
            try
            {
                getConnection getCon = new getConnection();
                oledCon = getCon.OledCon();
                oledCon.Open();
                string struse = "select * from House_Table where houseid='" + tb_aut.Strhouseid + "'";
                oledcmd = new OleDbCommand(struse, oledCon);
                oleRed = oledcmd.ExecuteReader();
                oleRed.Read();
                if ((int)oleRed[1] == 0)
                {
                    int usetime = (int)oleRed[2] + 1;
                    string strupdate = "update House_Table set housestay='" + tb_aut.Bolhousestay + "',usetime='" + usetime + "',vipname='" + tb_aut.Strvipname + "',vipid='" + tb_aut.Strvipid + "',usedate=#" + DateTime.Now + "# where houseid='" + tb_aut.Strhouseid + "'";
                    oledcmd = new OleDbCommand(strupdate, oledCon);
                    intResult = oledcmd.ExecuteNonQuery();
                    oleRed.Close();
                }
                return intResult;
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message.ToString());
                return intResult;
            }
        }
        /// <summary>
        /// 用于统计会员入住次数
        /// </summary>
        /// <param name="vipname"></param>
        /// <returns></returns>
        public int tbVipTime(string vipname)
        {
            int Viptime = 0;
            try
            {
                getConnection getCon = new getConnection();
                oledCon = getCon.OledCon();
                oledCon.Open();
                string strdel = "select * from Vip_Table where vipname='" + vipname + "'";
                oledcmd = new OleDbCommand(strdel, oledCon);
                oleRed = oledcmd.ExecuteReader();
                oleRed.Read();
                Viptime = (int)oleRed[3];
                oleRed.Close();
                return Viptime;

            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message.ToString());
                return Viptime;
            }
        }
        /// <summary>
        /// 对会员表次数进行操作  
        /// </summary>
        /// <param name="vipname"></param>
        /// <param name="time"></param>
        /// <returns></returns>
        public int tbVipTableUse(string vipname,int time)
        {
            int intResult = 0;
            try
            {
                getConnection getCon = new getConnection();
                oledCon = getCon.OledCon();
                oledCon.Open();
                string struse = "select * from Vip_Table where vipname='" + vipname + "'";
                oledcmd = new OleDbCommand(struse, oledCon);
                oleRed = oledcmd.ExecuteReader();
                oleRed.Read();
                int alltime = (int)oleRed[4] + 1;
                string strupdate = "update Vip_Table set givetime='"+time+"',alltime='"+alltime+"' where vipname='" + vipname + "'";
                oledcmd = new OleDbCommand(strupdate, oledCon);
                intResult = oledcmd.ExecuteNonQuery();
                oleRed.Close();
                return intResult;

            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message.ToString());
                return intResult;
            }
        }
        /// <summary>
        /// 将房间信息添加到退房窗体
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="img"></param>
        public void tbLeavefoFill(object obj, ImageList img)
        {
            try
            {
                getConnection getCon = new getConnection();
                oledCon = getCon.OledCon();
                oledCon.Open();
                string strRed = "select * from House_Table";
                oledcmd = new OleDbCommand(strRed, oledCon);
                oleRed = oledcmd.ExecuteReader();
                ListView lv = (ListView)obj;
                lv.Items.Clear();
                lv.LargeImageList = img;
                while (oleRed.Read())
                {
                    if ((int)oleRed[1] == 1)
                    {
                        lv.Items.Add(oleRed[0].ToString(), 0);
                    }
                }
                oleRed.Close();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message.ToString());
            }
        }
        /// <summary>
        /// 退房界面显示对应的信息
        /// </summary>
        /// <param name="strshow"></param>
        /// <returns></returns>
        public tb_viphouseinfo tbLeavetoshow(string strshow)
        {
            _aut1 = new tb_viphouseinfo();
            try
            {
                getConnection getCon = new getConnection();
                oledCon = getCon.OledCon();
                oledCon.Open();
                string strRed = "select * from House_Table where houseid='" + strshow + "'";
                oledcmd = new OleDbCommand(strRed, oledCon);
                oleRed = oledcmd.ExecuteReader();
                oleRed.Read();
                _aut1.Strhouseid = oleRed[0].ToString();
                _aut1.Strvipid = oleRed[3].ToString();
                _aut1.Strvipname = oleRed[4].ToString();
                _aut1.Dtusedate = (DateTime)oleRed[5];
                oleRed.Close();
                string strvip = "select * from Vip_Table where vipid='" + _aut1.Strvipid + "'and vipname='"+_aut1.Strvipname+"' ";
                oledcmd = new OleDbCommand(strvip, oledCon);
                oleRed = oledcmd.ExecuteReader();
                oleRed.Read();
                if(oleRed.HasRows)
                {
                    _aut1.Strvipidcard = oleRed[2].ToString();
                }
                else
                {
                    _aut1.Strvipidcard = _aut1.Strvipid;
                }
                oleRed.Close();
                return _aut1;
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message.ToString());
                return _aut1;
            }
        }
        /// <summary>
        /// 退房界面模糊查询
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="img"></param>
        /// <param name="strfind"></param>
        public void tbLezvefoFind(object obj, ImageList img, string strfind)
        {
            try
            {
                getConnection getCon = new getConnection();
                oledCon = getCon.OledCon();
                oledCon.Open();
                string strRed = "select * from House_Table where houseid like '%" + strfind + "%'";
                oledcmd = new OleDbCommand(strRed, oledCon);
                oleRed = oledcmd.ExecuteReader();
                ListView lv = (ListView)obj;
                lv.Items.Clear();
                lv.LargeImageList = img;
                while (oleRed.Read())
                {
                    if (oleRed[1].ToString() == "1")
                    {
                        lv.Items.Add(oleRed[0].ToString(), 0);
                    }
                }
                oleRed.Close();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message.ToString());
            }
            
        }
        /// <summary>
        /// 退房时写入记录
        /// </summary>
        /// <param name="tbrecord"></param>
        /// <returns></returns>
        public int tbWriteRecord(tb_viphouseinfo tbrecord)
        {
            int intResesult = 0;
            try
            {
                getConnection getCon = new getConnection();
                oledCon = getCon.OledCon();
                oledCon.Open();
                string strAdd = "insert into House_Record(houseid,vipid,vipname,vipidcard,usedate,leavedate,date11) values ('" + tbrecord.Strhouseid + "','" + tbrecord.Strvipid + "','" + tbrecord.Strvipname + "','" + tbrecord.Strvipidcard + "','" + tbrecord.Dtusedate + "','" + tbrecord.Dtleavedate + "','" + tbrecord.Strdate + "')";
                oledcmd = new OleDbCommand(strAdd, oledCon);
                intResesult = oledcmd.ExecuteNonQuery();
                return intResesult;
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message.ToString());
                return intResesult;
            }
        }
        /// <summary>
        /// 退房后更改房间信息
        /// </summary>
        /// <param name="houseid"></param>
        /// <returns></returns>
        public int tbhousefoLeave(string houseid)
        {
            int intResult = 0;
            try
            {
                getConnection getCon = new getConnection();
                oledCon = getCon.OledCon();
                oledCon.Open();
                string struse = "update House_Table set housestay='"+0+"',vipid='"+""+"',vipname='"+""+"' where houseid='" + houseid + "'";
                oledcmd = new OleDbCommand(struse, oledCon);
                intResult = oledcmd.ExecuteNonQuery();
                return intResult;
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message.ToString());
                return intResult;
            }
        }
        /// <summary>
        /// 设置开机运行
        /// </summary>
        /// <param name = "fileName" ></ param >
        /// < param name="isAutoRun"></param>
        //public void SetAutoRun(string fileName, bool isAutoRun)
        //{
        //    RegistryKey reg = null;
        //    try
        //    {
        //        if (!System.IO.File.Exists(fileName))
        //            throw new Exception("该文件不存在!");
        //        String name = fileName.Substring(fileName.LastIndexOf(@"\") + 1);
        //        reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
        //        if (reg == null)
        //            reg = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
        //        if (isAutoRun)
        //            reg.SetValue(name, fileName);
        //        else
        //            reg.SetValue(name, false);

        //    }
        //    catch
        //    {

        //        throw new Exception(ex.ToString());
        //    }
        //    finally
        //    {
        //        if (reg != null)
        //            reg.Close();
        //    }
        //}
    }
}
